package cn.vehicle.controller;

import cn.vehicle.annotations.NoAuthCheck;
import cn.vehicle.biz.SysUserBiz;
import cn.vehicle.domains.vo.BasePage;
import cn.vehicle.domains.vo.Result;
import cn.vehicle.domains.vo.req.sysUser.*;
import cn.vehicle.domains.vo.res.sysUser.SysUserRes;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
@Slf4j
@NoAuthCheck
@Tag(name = "SysUserController", description = "用户管理相关接口")
public class SysUserController {

    @Resource
    private SysUserBiz sysUserBiz;

    @PostMapping("/add")
    @Operation(description = "创建用户接口")
    public Result<Void> addUser(@RequestBody @Valid AddUserReq req) {
        sysUserBiz.addUser(req);
        return Result.success();
    }


    @PostMapping("/updateUser")
    @Operation(description = "创建用户接口")
    public Result<Void> updateUser(@RequestBody @Valid UpdateUserReq req) {
        sysUserBiz.updateUser(req);
        return Result.success();
    }

    @PostMapping("/deleteUser")
    @Operation(description = "删除用户接口")
    public Result<Void> deleteUser(
            @Parameter(schema = @Schema(name = "id", description = "用户id"))
            @RequestParam Long id) {
        sysUserBiz.deleteUser(id);
        return Result.success();
    }

    @PostMapping("/getUserById")
    @Operation(description = "查询用户接口")
    @NoAuthCheck
    public Result<SysUserRes> getUserById(Long id) {
        return Result.success(sysUserBiz.getUserById(id));
    }

    @PostMapping("/list")
    @Operation(description = "分页查询用户接口")
    public Result<BasePage<SysUserRes>> list(@RequestBody @Valid UserListReq req) {
        return Result.success(sysUserBiz.list(req));
    }


    @PostMapping("/addUserRoles")
    @Operation(description = "添加用户角色")
    public Result<Void> addUserRoles(@RequestBody @Valid AddUserRoleReq req) {
        sysUserBiz.addUserRoles(req);
        return Result.success();
    }

    @PostMapping("/login")
    @Operation(description = "用户登陆")
    public Result<SysUserRes> login(@RequestBody @Valid UserLoginReq req) {
        return Result.success(sysUserBiz.login(req));
    }
}
